#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace GrapplingHookGame
{
    /// <summary>
    /// Helper class represents a single entry in a MenuScreen that can choose between several values.
    /// Left and right will choose a different value.
    /// </summary>
    class ChoiceMenuEntry : MenuEntry
    {
        #region Fields

        /// <summary>
        /// The text choices rendered for this entry.
        /// </summary>
        string[] choices;

        private int currentChoice = 0;
        private string label = null;
        #endregion


        #region Properties


        /// <summary>
        /// Gets the text selected of this menu entry.
        /// </summary>
        public string SelectedText
        {
            get { return choices[currentChoice]; }
        }

        /// <summary>
        /// Optional label to enter before the choice
        /// </summary>
        public string Label
        {
            get { return label; }
            set { label = value; UpdateText(); }
        }

        #endregion

        #region Initialization


        /// <summary>
        /// Constructs a new menu entry with the specified text.
        /// </summary>
        public ChoiceMenuEntry(string[] choices)
            : base(choices[0])
        {
            this.choices = choices;
            UpdateText();
        }


        #endregion

               #region Events

        /// <summary>
        /// Method for raising the Left event.M ust be overridden to be used.
        /// </summary>
        protected internal override void OnLeftEntry()
        {
            if (currentChoice > 0)
            {
                currentChoice--;
                UpdateText();
            }
        }

        /// <summary>
        /// Method for raising the Right event. Must be overridden to be used.
        /// </summary>
        protected internal override void OnRightEntry()
        {
            if (currentChoice < choices.Length-1) 
            {
                currentChoice++;
                UpdateText();
            }
        }

        #endregion

        /// <summary>
        /// Updates the text drawn based on choice
        /// </summary>
        private void UpdateText()
        {
            //add arrows
            if (currentChoice == 0) Text = choices[currentChoice] + ">";
            else if (currentChoice == choices.Length - 1) Text = "<" + choices[currentChoice];
            else Text = "<" + choices[currentChoice] + ">";

            //add label
            if (Label != null) Text = Label + Text;
        }

        #region Update and Draw



        /// <summary>
        /// Draws the menu entry. This can be overridden to customize the appearance.
        /// </summary>
        public override void Draw(MenuScreen screen, Vector2 position,
                                 bool isSelected, GameTime gameTime)
        {
            base.Draw(screen, position, isSelected, gameTime);
        }



        #endregion
    }
}